package com.zpark.controller;

import com.zpark.mapper.IRankingMapper;
import com.zpark.pojo.Ranking;
import com.zpark.service.IRankingRepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

    @RestController
    public class RankingController {
        @Autowired
        private IRankingRepositoryService rankingService;


        @RequestMapping("/all")
        public List<Ranking> selectAll(){
            return rankingService.findAll();
        }


        @RequestMapping("/delete/{id}")
        public String delete(@PathVariable Integer id){
            rankingService.remove(id);
            return "数据删除成功！";
        }


        @RequestMapping("/update")
        public String updateRanking(@RequestBody Ranking ranking){
            rankingService.change(ranking);
            return "数据修改成功！";
        }


        @RequestMapping("/add")
        public void addRanking(@RequestBody Ranking ranking){
            rankingService.add(ranking);
        }



        @RequestMapping("/find_by_page/{starPage}/{size}")
        public Page<Ranking> findByPage(@PathVariable Integer starPage, @PathVariable Integer size){
            return rankingService.findPage(starPage,size);
        }

        @RequestMapping("/find_by_filmName/{filmName}")
        public List<Ranking> findByfilmName(@PathVariable String filmName){
            return rankingService.findByMovieName(filmName);
        }
    }
